package com.fps.web.dao.impl;
import org.springframework.stereotype.Repository;
import com.fpswork.core.exception.exception.BusinessException;
import com.fpswork.core.model.PageEntity;
import com.fpswork.datamodel.basedao.BaseDao;
import com.fpswork.util.BeanUtils;
import com.fpswork.util.StringUtil;
import com.fps.web.dao.MminfoDao;
import com.fps.web.model.Mminfo;
@Repository 
public class MminfoDaoImpl extends BaseDao implements MminfoDao{
    
	public PageEntity queryMminfoList(PageEntity pageEntity)  throws BusinessException{
		String sql="select * from mminfo";
		pageEntity.setSql(sql);
		return  this.queryForPageEntity(pageEntity);
	}
	public Mminfo queryMminfoByID(String id)  throws BusinessException{
		return  this.get(Mminfo.class, id);
	}
	public Mminfo addMminfo(Mminfo mminfo)  throws BusinessException{
		//校验是否为空
		if(mminfo==null){
			throw new BusinessException("传入数据为空！");
		}
		if(StringUtil.isEmpty(mminfo.getId())){
			this.save(mminfo);
		}else{
			throw new BusinessException("已存在数据！");
		}
		return mminfo;
	}
	public Mminfo updateMminfo(Mminfo mminfo)  throws BusinessException{
		Mminfo mminfo1= this.get(Mminfo.class, mminfo.getId());
		if(mminfo1==null||StringUtil.isEmpty(mminfo1.getId())){
	 		throw new BusinessException("没有找到数据！");
		}else{
			BeanUtils.copyProperties(mminfo1, mminfo);
			this.update(mminfo1);
		}
		return mminfo1;
	}
	public Boolean deleteMminfo(Mminfo mminfo)  throws BusinessException{
		this.delete(this.get(Mminfo.class, mminfo.getId()));
		
		return true;
	}
}
